package com.example.forumadminbackend.service.impl;

import com.example.forumadminbackend.entity.Admin;
import com.example.forumadminbackend.mapper.AdminMapper;
import com.example.forumadminbackend.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(String username, String password) {
        Admin admin = adminMapper.selectByUsername(username);
        if (admin != null && admin.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) {
            return admin;
        }
        return null;
    }

    @Override
    public Admin findById(String adminId) {
        return adminMapper.selectById(adminId);
    }
} 